#include "VisibleRect.h"
CCRect VisibleRect::VISIBLE_RECT;

void VisibleRect::lazyInit()
{
	if (VISIBLE_RECT.size.width == 0.0f && VISIBLE_RECT.size.height == 0.0f)
	{
		CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
		VISIBLE_RECT.origin = pEGLView->getVisibleOrigin();
		VISIBLE_RECT.size = pEGLView->getVisibleSize();
	}
}

CCRect VisibleRect::getVisibleRect()
{
	lazyInit();
	return CCRectMake(VISIBLE_RECT.origin.x, VISIBLE_RECT.origin.y, VISIBLE_RECT.size.width, VISIBLE_RECT.size.height);
}

CCPoint VisibleRect::left()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x, VISIBLE_RECT.origin.y+VISIBLE_RECT.size.height/2);
}

CCPoint VisibleRect::right()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x+VISIBLE_RECT.size.width, VISIBLE_RECT.origin.y+VISIBLE_RECT.size.height/2);
}

CCPoint VisibleRect::top()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x+VISIBLE_RECT.size.width/2, VISIBLE_RECT.origin.y+VISIBLE_RECT.size.height);
}

CCPoint VisibleRect::bottom()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x+VISIBLE_RECT.size.width/2, VISIBLE_RECT.origin.y);
}

CCPoint VisibleRect::center()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x+VISIBLE_RECT.size.width/2, VISIBLE_RECT.origin.y+VISIBLE_RECT.size.height/2);
}

CCPoint VisibleRect::leftTop()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x, VISIBLE_RECT.origin.y+VISIBLE_RECT.size.height);
}

CCPoint VisibleRect::rightTop()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x+VISIBLE_RECT.size.width, VISIBLE_RECT.origin.y+VISIBLE_RECT.size.height);
}

CCPoint VisibleRect::leftBottom()
{
	lazyInit();
	return VISIBLE_RECT.origin;
}

CCPoint VisibleRect::rightBottom()
{
	lazyInit();
	return ccp(VISIBLE_RECT.origin.x+VISIBLE_RECT.size.width, VISIBLE_RECT.origin.y);
}
